package com.gitee.jmliu1983.finacehelper.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gitee.jmliu1983.finacehelper.annotation.LogExecutionTime;
//import com.ruoyi.common.log.annotation.Log;
//import com.ruoyi.common.log.enums.BusinessType;
//import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.gitee.jmliu1983.finacehelper.domain.Product;
import com.gitee.jmliu1983.finacehelper.service.IProductService;
import com.ruoyi.common.annotation.Log;
//import com.ruoyi.common.core.web.controller.BaseController;
//import com.ruoyi.common.core.web.domain.AjaxResult;
//import com.ruoyi.common.core.utils.poi.ExcelUtil;
//import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * product_funcController
 * 
 * @author jm
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/product")
@PreAuthorize("@ss.hasRole('finace')")
public class ProductController extends BaseController
{
	private static final Logger LOGGER = LoggerFactory.getLogger(ProductController.class);
	
    @Autowired
    private IProductService productService;

    /**
     * 查询product_func列表
     */
    @GetMapping("/list")
    @LogExecutionTime(value="示例方法")
//    @PreAuthorize("@ss.hasPermi('finace:product:list')")
    public TableDataInfo list(Product product)
    {
        startPage();
       List<Product> list = productService.selectProductList(product);
        // List<Product> list = new ArrayList<Product>();
        return getDataTable(list);
    }

    /**
     * 导出product_func列表
     */
//    @RequiresPermissions("finace:product:export")
//    @Log(title = "product_func", businessType = BusinessType.EXPORT)
//    @PreAuthorize("@ss.hasPermi('finace:product:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Product product)
    {
        List<Product> list = productService.selectProductList(product);
        ExcelUtil<Product> util = new ExcelUtil<Product>(Product.class);
        util.exportExcel(response, list, "product_func数据");
    }

    /**
     * 获取product_func详细信息
     */
//    @RequiresPermissions("finace:product:query")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(productService.selectProductByProductId(productId));
    }

    /**
     * 新增product_func
     */
//    @RequiresPermissions("finace:product:add")
//    @Log(title = "product_func", businessType = BusinessType.INSERT)
    @PostMapping
    @PreAuthorize("@ss.hasPermi('finace:product:add')")
    public AjaxResult add(@RequestBody Product product)
    {
        return toAjax(productService.insertProduct(product));
    }

    /**
     * 修改product_func
     */
//    @RequiresPermissions("finace:product:edit")
//    @Log(title = "product_func", businessType = BusinessType.UPDATE)
    @PutMapping
    @PreAuthorize("@ss.hasPermi('finace:product:edit')")
    public AjaxResult edit(@RequestBody Product product)
    {
        return toAjax(productService.updateProduct(product));
    }

    /**
     * 删除product_func
     */
//    @RequiresPermissions("finace:product:remove")
//    @Log(title = "product_func", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('finace:product:remove')")
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(productService.deleteProductByProductIds(productIds));
    }
}
